@extends('layouts.admin')

@section('title', '编辑用户')

@section('content')
    <div class="static-content">
        <div class="page-content">
            <ol class="breadcrumb">
                <li class=""><a href="{{url('/admin')}}">Home</a></li>
                <li ><a href="{{url('/admin/user')}}">User</a></li>
                <li class="active"><a href="{{url('/admin/user/edit')}}">Edit</a></li>
            </ol>
            <div class="container-fluid">
                <div data-widget-group="group1">
                    <div class="row">
                        <div class="col-xs-12">
                            @if (Session::has('er'))
                                <div class="alert alert-dismissable alert-danger" style="visibility: visible; opacity: 1; display: block; transform: translateY(0px);">
                                    <i class="ti ti-timer"></i>&nbsp; <strong>Error:</strong>{{Session::get('er')}}
                                    <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                                </div>
                            @endif

                            @if (Session::has('success'))
                                <div class="alert alert-dismissable alert-success" style="visibility: visible; opacity: 1; display: block; transform: translateY(0px);">
                                    <i class="ti ti-check"></i>&nbsp; <strong>Success:</strong>{{Session::get('success')}}
                                    <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                                </div>
                            @endif
                            <div class="panel panel-midnightblue">
                                <div class="panel-heading">
                                    <div class="col-lg-10" style="height: 50px">
                                        <form action="{{url('/admin/user/edit')}}" method="get" class="col-lg-10">
                                            <div class="form-group">
                                                <label for="id" class="col-sm-2 control-label h5" style="width: auto !important;">编辑用户:</label>
                                                @if(!empty($user))
                                                    <div class="col-lg-4 h5">{{$user->name}}</div>
                                                @else
                                                    <div class="col-sm-8" style="margin-top: 10px !important;">
                                                        <input name="id" placeholder="输入用户uid" type="number" class="form-control" style="width: 250px !important;">
                                                    </div>
                                                @endif
                                            </div>
                                        </form>
                                    </div>
                                    <div class="panel-ctrls" data-actions-container="" data-action-collapse='{"target": ".panel-body, .panel-footer"}'></div>
                                </div>
                                <div class="panel-body">
                                    <form class="form-horizontal row-border" action="{{url('/admin/user/info/update')}}" method="post" id="form-horizontal" accept-charset="UTF-8" enctype="multipart/form-data">
                                        {{csrf_field()}}
                                        {{ method_field('PATCH') }}
                                        @if (!empty($user))
                                            <input type="hidden" name="uid" value="{{$user->id or 0}}">
                                        @endif
                                        <div class="form-group">
                                            <label class="col-sm-3 control-label">新密码</label>
                                            <div class="col-sm-6">
                                                <input type="password" data-parsley-range="[8, 64]" placeholder="重设密码" class="form-control" name="password">
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-sm-3 control-label">昵称</label>
                                            <div class="col-sm-6">
                                                <input type="text" data-parsley-maxlength="32" placeholder="用户昵称" required class="form-control" value="{{$user->name or ''}}"  name="name">
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-sm-3 control-label">Email</label>
                                            <div class="col-sm-6">
                                                <input type="email" data-parsley-maxlength="64" data-parsley-type="email" placeholder="邮箱" required class="form-control" value="{{$user->email or ''}}" name="email">
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-sm-3 control-label">真实姓名</label>
                                            <div class="col-sm-6">
                                                <input type="text" data-parsley-maxlength="32" placeholder="真实姓名" class="form-control" value="{{$user->truename or ''}}" name="truename">
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-sm-3 control-label">城市</label>
                                            <div class="col-sm-6">
                                                <input type="text" data-parsley-maxlength="32" placeholder="城市" class="form-control" value="{{$user->city or ''}}" name="city">
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-sm-3 control-label">公司</label>
                                            <div class="col-sm-6">
                                                <input type="text" data-parsley-maxlength="32" placeholder="公司" class="form-control" value="{{$user->company or ''}}" name="company">
                                            </div>
                                        </div>

                                        <div class="form-group">
                                            <label class="col-sm-3 control-label">微博用户名</label>
                                            <div class="col-sm-6">
                                                <input type="text" data-parsley-range="[1,32]" placeholder="微博用户名" class="form-control" value="{{$user->weiboname or ''}}" name="weiboname">
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-sm-3 control-label">微博个人页面</label>
                                            <div class="col-sm-6">
                                                <input type="text" data-parsley-type="url" data-parsley-maxlength="255" placeholder="微博个人页面" class="form-control" value="{{$user->weibourl or ''}}" name="weibourl">
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-sm-3 control-label">个人网站</label>
                                            <div class="col-sm-6">
                                                <input type="text" data-parsley-type="url" data-parsley-maxlength="255" placeholder="个人网站" class="form-control" value="{{$user->weblink or ''}}" name="weblink">
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-sm-3 control-label">头像</label>
                                            <div class="col-sm-6">
                                                <input type="file" class="form-control" name="profile">
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-sm-3 control-label">微信账号二维码</label>
                                            <div class="col-sm-6">
                                                <input type="file" class="form-control" name="wechatqrcode">
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-sm-3 control-label">支付二维码</label>
                                            <div class="col-sm-6">
                                                <input type="file" class="form-control" name="paymentqrcode">
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-sm-3 control-label">个人简介</label>
                                            <div class="col-sm-6">
                                                <textarea type="text" class="form-control" data-parsley-maxlength="255" name="introduction">{{$user->introduction or ''}}</textarea>
                                            </div>
                                        </div>
                                        @if (!empty($user))
                                            <div class="form-group">
                                                <label for="role" class="col-sm-3 control-label">Role</label>
                                                <div class="col-sm-6">
                                                    <select class="form-control" name="role_id" id="role" required>
                                                        <option value="{{$user->userRole->role->id or 0}}">Old:{{$user->userRole->role->display_name or '错误'}}</option>
                                                        @if (!empty($roles))
                                                            @foreach($roles as $role)
                                                                <option value="{{$role->id or 0}}">{{$role->display_name or ''}}</option>
                                                            @endforeach
                                                        @endif
                                                    </select>
                                                </div>
                                            </div>
                                            <div class="form-group">
                                                <label for="ban" class="col-sm-3 control-label">Ban</label>
                                                <div class="col-sm-6">
                                                    <select class="form-control" name="ban_time" id="ban">
                                                        @if($user->is_ban != 0 && $user->ban_time > time())
                                                            <option selected>封禁至：{{date('Y/m/d H:i:s', $user->ban_time)}} </option>
                                                        @elseif ($user->is_ban == -1)
                                                            <option>永久封禁</option>
                                                        @else
                                                            <option>选择时间</option>
                                                        @endif
                                                        <option value="1800">30分钟</option>
                                                        <option value="3600">1小时</option>
                                                        <option value="7200">2小时</option>
                                                        <option value="43200">12小时</option>
                                                        <option value="86400">一天</option>
                                                        <option value="172800">两天</option>
                                                        <option value="604800">一周</option>
                                                        <option value="1209600">两周</option>
                                                        <option value="2592000">一月</option>
                                                        <option value="9999">永久</option>
                                                        <option value="7777">解除封禁</option>
                                                    </select>
                                                </div>
                                            </div>
                                            <div class="form-group">
                                                <label class="col-sm-3 control-label">激活</label>
                                                <div class="col-sm-6">
                                                    <div class="checkbox">
                                                        <label>
                                                            <input type="checkbox" name="bind_steam"
                                                            @if (!empty($user->getSteamUser))
                                                                checked
                                                            @else
                                                                disabled
                                                            @endif
                                                            >绑定Steam
                                                        </label>
                                                </div>
                                            </div>
                                        </div>
                                        @endif
                                        <div class="form-group">
                                            <label class="col-sm-3 control-label">激活</label>
                                            <div class="col-sm-6">
                                                <div class="checkbox">
                                                    <label>
                                                        <input type="checkbox" name="verified"
                                                        @if (!empty($user))
                                                            {{$user->verified == 1 ? 'checked' : ''}}
                                                                @endif
                                                        >账户邮箱激活
                                                        </label>
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="panel-footer">
                                                <div class="row">
                                                    <div class="col-sm-6 col-sm-offset-3">
                                                        <div class="btn-toolbar">
                                                            <button class="btn btn-default">提交</button>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </form>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
@endsection

@section('js')
    <script src="{{cdn('/supervise/assets/plugins/form-parsley/parsley.js')}}"></script>
    <script>
        // See Docs
        window.ParsleyConfig = {
            successClass: 'has-success'
            , errorClass: 'has-error'
            , errorElem: '<span></span>'
            , errorsWrapper: '<span class="help-block"></span>'
            , errorTemplate: "<div></div>"
            , classHandler: function(el) {
                return el.$element.closest(".form-group");
            }
        };
        $(document).ready(function () {
            let $form = $('#form-horizontal');
            $('#form-horizontal .btn').on('click', function () {
                if ($form.parsley().validate() == true){
                    $form.submit();
                }
            });
        });
    </script>
@endsection